/**
 * Classe permettant l'affichage d'un ascenseur
 * @authors: Bertrand GUILLAUMOND
 * @version 1.0
 */

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ElevatorPanel extends JPanel
{
	private int panelFloor;
	private Elevator ev;
	private String destination;
	private int dest;
	private int nbUsers;
	boolean called;
	private final Image caller = Toolkit.getDefaultToolkit().getImage("caller.gif");
	private final Image out = Toolkit.getDefaultToolkit().getImage("out.gif");

	public ElevatorPanel(int f, Elevator e){
		if(f <= 44 && f >= 0)
			panelFloor = f;
		else
			panelFloor = 0;
		destination = "RDC";
		called = false;
		setBackground(new Color(200,200,200));
		nbUsers = 0;
		ev = e;
	}

	public Elevator getElevator()
	{
		return ev;
	}

	public void setDestinationString(String d)
	{
		destination = d ;
	}

	public void setFloor(int f)
	{
		if(f <= 44 && f >= 0)
		panelFloor = f;
		repaint();
	}
	
	public void setCalled(boolean c)
	{
		called = c;
	}

	public int getFloor()
	{
		return panelFloor;
	}

	public void setDestination(int d)
	{
		if(d <= 44 && d >= 0)
		dest = d;
	}

	public int getDestination()
	{
		return dest;
	}
	
	public void setNbUsers(int n)
	{
		nbUsers = n;
	}

	public void paintComponent(Graphics g){
		super.paintComponent(g);
		Vector<Customer> callers = ev.getCallers();
		Vector<Customer> customers = ev.getCustomers();
		for(int i = 0;i < customers.size(); i++)
		{
			Customer c = customers.get(i);
			if(c.getDestination() == panelFloor)
				g.drawImage(out,5,660 - 15 * ev.getFloor(),this);
		}	
	
		for(int i = 0;i < callers.size(); i++)
		{
			Customer c = callers.get(i);

			g.drawImage(caller,5,660 - 15 * c.getCurrentFloor(),this);
		}
		g.setFont(new Font("verdana", 0, 10));
		setDestinationString("Vers E" + (ev.getCurrentDestination() - 4)+".");
		setNbUsers(ev.getCustomers().size());
		for(int i = -1; i <= 44; i++)
			g.drawLine(15,660 - i * 15,65,660- i * 15);
		g.draw3DRect(15,0,50,673, true);
		g.drawString("E."+(panelFloor - 4)+"U:"+nbUsers,20,660 - (15 * panelFloor) + 12);
				
		g.draw3DRect(17,660 - (15 * panelFloor)+1,46,13, true);	
		g.drawString(destination ,17,700);
		
		g.finalize();
	}
}
